package net.m2technologies.open_arm.transport.formatters;

/**
 * Copyright 2005 Mark Masterson<br> <br> Licensed under the Apache License, Version 2.0 (the "License");<br> you may
 * not use this file except in compliance with the License.<br> You may obtain a copy of the License at<br> <br>
 * http://www.apache.org/licenses/LICENSE-2.0<br> <br> Unless required by applicable law or agreed to in writing,
 * software<br> distributed under the License is distributed on an "AS IS" BASIS,<br> WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied.<br> See the License for the specific language governing permissions and<br>
 * limitations under the License.<br>
 * <p/>
 * <p>Description: This class handles the internationalization and formatting of the text message used for #blocked
 * events of the ArmTransaction interface.</p>
 *
 * @author Mark Masterson
 * @version 0.010
 */
public class DefaultBlockedMessageFormatterImpl extends AbstractMessageFormatterImpl
        implements BlockedMessageFormatter {

    public final String getBlockedMessage(final long tmpHandle,
                                          final String transactionID,
                                          final String transactionName,
                                          final String applicationName,
                                          final String parentCorrelator) {
        return new StringBuffer().append(getResources().getString("blocked_message_trans_id"))
                .append(BLANK_SPACE)
                .append(transactionID)
                .append(getResources().getString("message_trans_name"))
                .append(BLANK_SPACE)
                .append(transactionName)
                .append(getResources().getString("message_app_name"))
                .append(BLANK_SPACE)
                .append(applicationName)
                .append(handleParentCorrelator(parentCorrelator))
                .append(BLANK_SPACE)
                .append(getResources().getString("blocked_message_text"))
                .append(BLANK_SPACE)
                .append(tmpHandle)
                .toString();
    }

    private String handleParentCorrelator(final String parentCorrelator) {
        return null != parentCorrelator && !"".equals(parentCorrelator)
               ? new StringBuffer().append(getResources().getString("message_parent_corr"))
                .append(BLANK_SPACE)
                .append(parentCorrelator).toString()
               : "";
    }

}
